package com.crr.mall.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.crr.mall.common.bean.ResultBean;
import com.crr.mall.common.utils.BaseController;
import com.crr.mall.common.utils.PageUtils;
import com.crr.mall.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.crr.mall.product.entity.CategoryBrandRelationEntity;
import com.crr.mall.product.service.CategoryBrandRelationService;


/**
 * 品牌分类关联
 *
 * @author chenrenren
 * @email chenrenren@gmail.com
 * @date 2024-12-06 17:50:14
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController extends BaseController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @GetMapping("/catelog/list")
    // @RequiresPermissions("product:categorybrandrelation:list")
    public ResultBean list(@RequestParam Map<String, Object> params) {
        PageUtils page = categoryBrandRelationService.queryPage(params);
        return success("品牌及分类关联表", page);
    }

    @GetMapping("/brands/list")
    public ResultBean queryBrand(@RequestParam("catId") Long catId) {
        List<Map> list = categoryBrandRelationService.queryByCatId(catId);
        return success("品牌列表", list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("product:categorybrandrelation:info")
    public R info(@PathVariable("id") Long id) {
        CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    // @RequiresPermissions("product:categorybrandrelation:save")
    public ResultBean save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation) {
        int i = categoryBrandRelationService.saveDetail(categoryBrandRelation);

        return saveResult(i);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("product:categorybrandrelation:update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation) {
        categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("product:categorybrandrelation:delete")
    public R delete(@RequestBody Long[] ids) {
        categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
